import time
from distutils.command.check import check
from pickletools import long1
from time import sleep

from Tools.scripts.cleanfuture import dryrun
from selenium.webdriver.common.by import By

from common.com import forum, Driver
#注册页面的测试
class signUp:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/sign-up.html"
        self.driver = forum.driver
        self.driver.get(self.url)
    #正常注册
    def snormal(self):
        #寻找输入框并清除内容
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        #进行输入
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("test222")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("测试员")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        #同意条框点击注册
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(1)
        #进行截图
        forum.getscreenshot()
        #验证登录成功后是否跳转到登录页面
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
    #异常注册
    def failsign(self):
        #测试用例一:不输入用户名，但输入昵称，密码，同意条款进行注册
        #寻找输入框并清除内容
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()
        #进行输入

        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("测试员")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        #同意条框点击注册
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(1)
        #进行截图
        forum.getscreenshot()
        #寻找用户名不能为空的提示内容验证测试结果
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(2) > div")
####################################################################
        #测试用例三：输入用户名，但输入昵称，密码，不同意条款进行注册
        # 寻找输入框并清除内容
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        # 进行输入
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("test222")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("测试员")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        time.sleep(1)
        checkbox = self.driver.find_element(By.CSS_SELECTOR, "#policy")
        if checkbox.is_selected():
            checkbox.click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(1)
        # 进行截图
        forum.getscreenshot()
        #检查是否还停用户注册界面来验证
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > h2")
#####################################################################
        # 测试用例四：不输入昵称，输入用户名，密码，同意条款进行注册
        # 寻找输入框并清除内容
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        # 进行输入
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("test222")

        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        # 进行截图
        forum.getscreenshot()
        # 寻找昵称不能为空的提示内容验证测试结果
        self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div")

#####################################################################
        # 测试用例四：不输入密码，输入昵称，密码，同意条款进行注册
        # 寻找输入框并清除内容
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").clear()

        #进行输入
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("test222")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("测试员")

        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("123")

        #同意条框点击注册
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR,"#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        # 进行截图
        forum.getscreenshot()
        #寻找提示框验证登录
        self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(4) > div > div")




signUP = signUp()
# signUP.snormal()
signUP.failsign()
